<template>
  <div class="divBox">
    <el-card class="box-card">
      <el-form inline size="small" @submit.native.prevent>
        <el-form-item label="关键词：">
          <el-input v-model="listPram.keyword" placeholder="手机号" clearable class="asWidth"/>
        </el-form-item>
        <el-form-item label="选择时间：">
          <el-date-picker
              v-model="value1"
              @change="handleChange"
              value-format="yyyy-MM-dd" format="yyyy-MM-dd"
              type="daterange"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              style="width: 300px"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="抽成类型:">
          <el-select v-model="listPram.type" placeholder="请选择" style="width: 200px;">
            <el-option
                v-for="item in typeList"
                :key="item.id"
                :label="item.name"
                :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="地区：" prop="areaId">
          <el-cascader class="col"
                       placeholder="可输入地区名称进行搜索"
                       v-model="value"
                       :options="options"
                       clearable
                       :props="{ expandTrigger: 'hover' }"
                       filterable
                       @change="handleChange1"></el-cascader>
        </el-form-item>
        <el-form-item>
          <el-button icon="el-icon-search" size="mini" type="primary" @click.native="getList">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
        <el-form-item style="margin-left: 10px">
          <span>平台总抽成 {{dataInfo.TotalPlatformVoucher}}</span>
          <span style="margin-left: 20px">市级总抽成 {{dataInfo.TotalCityVoucher}}</span>
          <span style="margin-left: 20px">区级总抽成 {{dataInfo.TotalAreaVoucher}}</span>
        </el-form-item>
      </el-form>
      <el-table :data="listData.list" size="mini" :header-cell-style=" {fontWeight:'bold',background:'#f8f8f9',color: '#515a6e',height:'40px'}" border>
<!--        <el-table-column label="ID" prop="id" width="120" ></el-table-column>-->
        <el-table-column label="消费用户手机号" prop="userPhone" width="130"/>
        <el-table-column label="抽成类型" prop="type" width="130">
         <template slot-scope="scope">
           <span v-if="scope.row.type==1">转账</span>
           <span v-if="scope.row.type==2">购买套餐</span>
           <span v-if="scope.row.type==3">兑换商品</span>
         </template>
        </el-table-column>
        <el-table-column label="总分成" prop="totalVoucher" width="130"/>
        <el-table-column label="平台获得" prop="plartformVoucher" min-width="130"/>
        <el-table-column label="市级区域" prop="city" min-width="130">
          <template slot-scope="scope">
           {{scope.row.city||'暂无'}}
          </template>
        </el-table-column>
        <el-table-column label="市代理获得" prop="cityVoucher" min-width="130"/>
        <el-table-column label="市代理账号" prop="cityUserPhone" min-width="130">
          <template slot-scope="scope">
            {{scope.row.cityUserPhone||'暂无'}}
          </template>
        </el-table-column>
        <el-table-column label="区级区域" prop="area" min-width="130"/>
        <el-table-column label="区代理获得" prop="areaVoucher" min-width="130"/>
        <el-table-column label="区代理账号" prop="areaUserPhone" min-width="130"/>
        <el-table-column label="时间" prop="createTime" min-width="150"/>
<!--        <el-table-column label="操作" min-width="180" fixed="right" align="center">-->
<!--          <template slot-scope="scope">-->
<!--            <el-button icon="el-icon-edit" size="mini" type="primary" @click="openEdit(scope.row.id,scope.row.ifVI)"  v-has-permi="['admin:circulation:detail']">详情</el-button>-->
<!--          </template>-->
<!--        </el-table-column>-->
      </el-table>
      <el-pagination
        :current-page="listPram.page"
        :page-sizes="[20,40,60,80,100]"
        layout="total, sizes, prev, pager, next, jumper"
        :total="listData.count"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </el-card>
    <el-dialog
      :visible.sync="editDialog.show"
      destroy-on-close
      :close-on-click-modal="false"
      width="1200px">
      <edit
        v-if="editDialog.show"
        :id="editDialog.id"
        :ifVI="editDialog.ifVI"
        @hideEditDialog="hideEditDialog"
        ref="editForm"
      />
    </el-dialog>
  </div>
</template>

<script>
import edit from './edit.vue'
import {dividedIntoRecordList,dataStatistics} from "@/api/vip";
import {checkPermi} from "@/utils/permission";
import {optionsList} from "@/api/business";
export default {
  components: { edit },
  data() {
    return {
      listData: { list: [],count:0 },
      listPram: {
        keyword: '',
        beginTime: null,
        endTime: null,
        areaId:'',
        page: 1,
        limit: 20,
        type:''
      },
      value1:'',
      editDialog:{
        show:false,
        id:null,
        ifVI:null
      },
      typeList:[
        {name:'转账',id:1},
        {name:'套餐购买',id:2},
        {name:'兑换商品',id:3},
      ],
      tableLoading:false,
      value: [],
      dataInfo:{},
      options: [{
        value: '',
        label: '',
        children: [{
          value: '',
          label: '',
          children: [{
            value: '',
            label: ''
          }]
        }]
      }],
    }
  },
  mounted() {
    this.getList()
    this.getOptions()
  },
  created() {
    if (this.$route.query.keyword) {
      this.listPram.keyword = this.$route.query.keyword
    }

  },
  methods: {
    handleChange1(value) {
      this.listPram.areaId = value[2]
    },
    getOptions() {
      optionsList().then(res => {
        this.options = res
      })
    },
    handleChange(value) {
      if (Array.isArray(value) && value.length === 2) {
        this.listPram.beginTime = value[0];
        this.listPram.endTime = value[1];
      }
    },
    checkPermi,
    getDataInfo()
    {
      dataStatistics(this.listPram).then(res=>{
        this.dataInfo=res;
        console.log(this.dataInfo)
      }).finally(()=>{})
    },
    getList(){
      this.tableLoading=true
      dividedIntoRecordList(this.listPram).then(res=>{
        this.listData=res;
      }).finally(()=>{
        this.getDataInfo()
      })
      this.tableLoading=false;
    },
    openEdit(id=null,ifVI=null){
      this.editDialog.id=id;
      this.editDialog.ifVI=ifVI;
      this.editDialog.show=true
    },
    hideEditDialog() {
      this.editDialog.show = false
      this.getList()
    },
    handleSizeChange(val) {
      this.listPram.limit = val
      this.getList()
    },
    handleCurrentChange(val) {
      this.listPram.page = val
      this.getList()
    },
    resetQuery(){
      this.listPram.keyword = '';
      this.value1 = '';
      this.listPram.beginTime = null;
      this.listPram.endTime = null;
      this.listPram.areaId = null;
      this.listPram.type=''
      this.value = ''
      this.getList()
    }
  }
}
</script>

<style scoped lang="scss">
.asWidth{
  width: 200px;
}
</style>
